<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    .img-box {
      width: 700px;
      height: 320px;
      margin: 50px auto 0;
      background: #000;
      position: relative;
    }
    .pic {
      width: 100%;
      height: 100%;
    }

    .img-box .tip {
      width: 700px;
      height: 53px;
      line-height: 53px;
      position: absolute;
      bottom: 0px;
      background-color: rgba(0, 0, 0, 0.8);
      z-index: 10;
    }

    .img-box .tip h3 {
      width: 82%;
      margin: 0;
      margin-right: 20px;
      padding-left: 20px;
      color: #98e404;
      font-size: 28px;
      float: left;
      font-weight: 500;
      font-family: 'Microsoft Yahei', Tahoma, Geneva;
    }

    .img-box .tip a {
      width: 30px;
      height: 29px;
      display: block;
      float: left;
      margin-top: 12px;
      margin-right: 3px;
    }

    .img-box ul {
      position: absolute;
      bottom: 0;
      right: 30px;
      list-style: none;
      z-index: 99;
    }
  </style>
  <body>
    <div class="img-box">
      <img class="pic" src="./images/slider01.jpg" alt="第1张图的描述信息" />
      <div class="tip">
        <h3 class="text">对人类来说会不会太超前了？</h3>
      </div>
    </div>
    <script>
      const data = [
        {
          url: './images/slider01.jpg',
          title: '对人类来说会不会太超前了？',
          color: 'rgb(100, 67, 68)',
        },
        {
          url: './images/slider02.jpg',
          title: '开启剑与雪的黑暗传说！',
          color: 'rgb(43, 35, 26)',
        },
        {
          url: './images/slider03.jpg',
          title: '真正的jo厨出现了！',
          color: 'rgb(36, 31, 33)',
        },
        {
          url: './images/slider04.jpg',
          title: '李玉刚：让世界通过B站看到东方大国文化',
          color: 'rgb(139, 98, 66)',
        },
        {
          url: './images/slider05.jpg',
          title: '快来分享你的寒假日常吧~',
          color: 'rgb(67, 90, 92)',
        },
        {
          url: './images/slider06.jpg',
          title: '哔哩哔哩小年YEAH',
          color: 'rgb(166, 131, 143)',
        },
        {
          url: './images/slider07.jpg',
          title: '一站式解决你的电脑配置问题！！！',
          color: 'rgb(53, 29, 25)',
        },
        {
          url: './images/slider08.jpg',
          title: '谁不想和小猫咪贴贴呢！',
          color: 'rgb(99, 72, 114)',
        },
      ]

      const img = document.querySelector('.pic')
      const text = document.querySelector('.tip .text')
      const color = document.querySelector('.tip')

      const title = setInterval(function () {
        const random = Math.floor(Math.random() * data.length)
        const randomData = data[random]
        img.src = randomData.url
        text.innerHTML = randomData.title
        color.style.backgroundColor = randomData.color
      }, 1000)
    </script>
  </body>
</html>
